

def Add():
    # 临时储存信息
    info = dict()
    print("******* 欢迎进入会员添加界面 *******")

    # 编号
    new_id = input("请输入需要添加会员的编号：")
    info["id"] = new_id

    # 姓名
    while True:
        new_user = input("请输入需要添加会员的姓名：")
        flag = 0
        for it in lt:
           for key, value in it.items():
               if value == new_user:
                   print("名字已存在，请重新输入")
                   flag = 1
                   break
        if flag==1:
            continue

        new_user_list = list(new_user)
        if any(user_1 in new_user for user_1 in no_user):
            k = 0
            old_ = []
            for i in new_user:
                for j in no_user:
                    # 找敏感字符
                    if i == j:
                        old_.append(new_user[k])
                        new_user_list[k] = '*'
                        new_user = ''.join(new_user_list)
                        break
                k += 1
            print(f"{new_user}|姓名包含敏感词{old_},不可注册,重新输入")
            continue
        break

    info["name"] = new_user

    # 手机号码
    while True:
        new_phone = input("请输入需要添加的手机号码：")
        info["phone"] = new_phone

        if any(user_1 in new_phone for user_1 in letters):
            print("手机号不能含有字母，请重新输入")
            continue

        if len(new_phone) != 11:
            print("手机号数目有误，请重新输入")
            continue
        break

    # 储存
    lt.append(info)
    print("您好！")
    print(f'您添加的编号为:{new_id}')
    print(f"您注册的姓名为 :{new_user}")
    print(f"您注册的手机号为 :{new_phone}")
    print("******* 已经添加成功！*******")
    print("")


def Delete():
    Find_name = input("请输入需要删除会员的姓名：")
    flag = 0
    Find = 0
    for it in lt:
        for key,value in it.items():
            if value ==Find_name:
                Find = flag
        flag += 1

    if Find != 0:
        lt.pop(Find)
        print("删除成功！")
        print("")
        Show()
        return 0
    else:
        print("未存在该会员")
        print("")


def Modify():
    in_put ==input("请输入需要修改信息的姓名：")
    flag = 0
    Find = 0
    for it in lt:
        for key, value in it.items():
            if value == in_put:
                Find = flag
        flag += 1
    if flag == len(lt)-1 and Find == 0 :
        print("用户不存在")
        return 0

    #查找下标
    flag = 0
    Find = 0
    for it in lt:
        for key, value in it.items():
            if value == in_put:
                Find = flag
        flag += 1
    # 删除需要修改的
    lt.pop(Find)
    ######################################
    #新建修改后的

    # 临时储存信息
    info = dict()
    # 编号
    new_id = input("请输入修改后的编号：")
    info["id"] = new_id

    # 姓名
    while True:
        new_user = input("请输入修改后的姓名：")
        new_user_list = list(new_user)
        if any(user_1 in new_user for user_1 in no_user):
            k = 0
            old_ = []
            for i in new_user:
                for j in no_user:
                    # 找敏感字符
                    if i == j:
                        old_.append(new_user[k])
                        new_user_list[k] = '*'
                        new_user = ''.join(new_user_list)
                        break
                k += 1
            print(f"{new_user}|姓名包含敏感词{old_},不可注册,重新输入")
            continue
        break

    info["name"] = new_user

    # 手机号码
    while True:
        new_phone = input("请输入修改后的手机号码：")
        info["phone"] = new_phone

        if any(user_1 in new_phone for user_1 in letters):
            print("手机号不能含有字母，请重新输入")
            continue

        if len(new_phone) != 11:
            print("手机号数目有误，请重新输入")
            continue
        break

    # 储存
    lt.insert(Find,info)
    print("您好！")
    print(f'修改后的编号为:{new_id}')
    print(f"修改后的姓名为 :{new_user}")
    print(f"修改后的手机号为 :{new_phone}")
    print("******* 已经修改成功！*******")
    print("")


def Find():
    in_put = input("请输入需要查询信息的姓名：")
    flag = 0
    Find = 9999
    for it in lt:
        for key, value in it.items():
            if value == in_put:
                Find = flag
        flag += 1
    if  Find == 9999:
        print("用户不存在")
        return 0
    print("会员信息：")
    flag_2 = 0
    for it in lt:
        flag_3 = 1
        for key, value in it.items():
            if flag_2 ==Find:
                if flag_3 == 1:
                    print(f"会员编号：{value}")
                    flag_3 += 1
                elif flag_3 == 2:
                    print(f"会员姓名：{value}")
                    flag_3 += 1
                elif flag_3 == 3:
                    print(f"会员手机号：{value}")
                    break
        flag_2 +=1
    print("")


def Show():
    print("会员信息：")
    for it  in lt:
        print("-----------------------")
        flag = 1
        for key,value in it.items():
            if flag==1:
                print(f"会员编号：{value}")
                flag +=1
            elif flag == 2:
                print(f"会员姓名：{value}")
                flag += 1
            elif flag == 3:
                print(f"会员手机号：{value}")
                break
        print("-----------------------")




#信息
lt = []
# 敏感字
no_user = ['笨', '蠢', '死']
#字母
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

if __name__=="__main__":
    while True:
        print("******* 欢迎使用会员登管理系统 *******")
        print("******* 请选择您需要使用的功能 *******")
        print("*******    1. 添加          *******")
        print("*******    2. 删除          *******")
        print("*******    3. 修改          *******")
        print("*******    4. 查询          *******")
        print("*******    5. 显示所有会员信息 ******")
        print("*******    6. 退出系统       *******")
        in_put = int(input("请输入："))
        if in_put == 1:
            Add()

        if in_put == 2:
            Delete()

        if in_put ==3:
            Modify()

        if in_put == 4:
            Find()

        if in_put == 5:
            Show()

        if in_put == 6:
            print("确定退出吗？(yse or no)")
            n = input("请输入：")
            if n == "yes":
                break
            elif n== 'no':
                print("")
                continue
            else:
                print("非法输入请重新选择功能")
                continue


